const express = require('express');
const router = express.Router();
const db = require('../db/index')
// 1. 获取轮播图数据
router.get('/slideshow', (req, res) => {
    const sql = 'select * from slideimg';
    db.query(sql, (err, result) => {
        if (err) return res.lose(err)
        res.send({
            statue: 0,
            success: true,
            message: '获取轮播图数据成功',
            result
        })
    })

})
// 2. 获取热门商品数据(查询分页)
// http://127.0.0.1:3006/home/hotshop
router.get('/hotshop', (req, res) => {
    //req 获取前端传递过来的数据
    // get req.query   post req.body 
    const sql = 'select * from hotshop limit ?,?'
    const qy = req.query;
    if (!qy.page) qy.page = 0;
    if (!qy.count) qy.count = 10;
    db.query(sql, [Number(qy.page), Number(qy.count)], (err, result) => {
        if (err) return res.lose(err)
        res.send({
            statue: 0,
            success: true,
            message: '获取热门商品数据成功！',
            result
        })
    })
})

// http://127.0.0.1:3006/home/slideshow

// 导出
module.exports = router